package com.ymatou.iapi.userservice.testcase;

import java.util.ArrayList;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.LockUserRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.UnLockUserRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.mongo.UserTokenWapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
*解锁用户接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UnLockUserRequestDto{
	private static LockUserRequestDtoBean unlockuserrequestdtoBean;
	private static UnLockUserRequestDtoCall unlockuserrequestdtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("解锁用户接口");
	}

	@Before
	public void caseUp() {
		unlockuserrequestdtoBean=new LockUserRequestDtoBean();
		unlockuserrequestdtoCall=new UnLockUserRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(unlockuserrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UnLockUserRequestDto_001() {
		Logger.start(true,"解锁用户,验证用户登录提示用户已解锁");
		try {			
			Logger.comment("注册一个新用户");
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			int userId = JUserCallService.createUserCall(cur);
			JUserCallService.lockUsers(userId);
			ArrayList<Integer> users=new ArrayList<Integer>();
			users.add(userId);
			Logger.comment("锁住用户");
			unlockuserrequestdtoBean.setUserId(users);
			unlockuserrequestdtoBean.setDescription("autotest");
			unlockuserrequestdtoBean.setOperating("auto");
			unlockuserrequestdtoCall.setData(unlockuserrequestdtoBean);
			unlockuserrequestdtoCall.callService();
			Logger.verifyEquals("true",unlockuserrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200",unlockuserrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(userId).get(0);
			Logger.verifyEquals(0,ui.getUserState(), "验证UserState0解锁");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_UnLockUserRequestDto_002() {
		Logger.start(true,"解锁多个用户,成功");
		try {		
			Logger.comment("注册一个新用户");
			ArrayList<Integer> userIds=new ArrayList<Integer>();
			String ip=TestDataManager.getRandomIp();
			for (int i=0;i<3;i++){
				Logger.comment("注册一个新用户");
				CreateUserReq cur=new CreateUserReq();
				cur=JUserCallService.initCreateUserBean(cur);
				int userId = JUserCallService.createUserCall(cur);
				userIds.add(userId);
			}	
			for (Integer userId : userIds) {
				JUserCallService.lockUsers(userId);
			}
			Logger.comment("解锁用户");
			unlockuserrequestdtoBean.setUserId(userIds);
			unlockuserrequestdtoBean.setDescription("autotest");
			unlockuserrequestdtoBean.setOperating("auto");
			unlockuserrequestdtoCall.setData(unlockuserrequestdtoBean);
			unlockuserrequestdtoCall.callService();
			Logger.verifyEquals("true",unlockuserrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200",unlockuserrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			
			for (Integer userId:userIds){
				Userinfo ui = new JUserWapper().selectUserinfoByUid(userId).get(0);
				Logger.verifyEquals(0,ui.getUserState(), "验证UserState0未锁定");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnLockUserRequestDto_003() {
		Logger.start(false,"用户id为空");
		try {			
			unlockuserrequestdtoBean.setDescription("autotest");
			unlockuserrequestdtoBean.setOperating("auto");
			unlockuserrequestdtoCall.setData(unlockuserrequestdtoBean);
			unlockuserrequestdtoCall.callService();			
			Logger.verifyIsContains("用户ID未提供",unlockuserrequestdtoCall.getString("LastErrorMessage"), "验证提示信息");
			Logger.verifyEquals("false",unlockuserrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100",unlockuserrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnLockUserRequestDto_004() {
		Logger.start(false,"操作为空");
		try {			
			unlockuserrequestdtoBean.setUserId(new ArrayList<Integer>());
			unlockuserrequestdtoBean.setDescription("autotest");
			unlockuserrequestdtoCall.setData(unlockuserrequestdtoBean);
			unlockuserrequestdtoCall.callService();			
			Logger.verifyIsContains("操作者不能为空",unlockuserrequestdtoCall.getString("LastErrorMessage"), "验证提示信息");
			Logger.verifyEquals("false",unlockuserrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100",unlockuserrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UnLockUserRequestDto_005() {
		Logger.start(false,"操作描述为空");
		try {			
			unlockuserrequestdtoBean.setUserId((ArrayList<Integer>)(new ArrayList<Integer>()));
			unlockuserrequestdtoBean.setOperating("autotest");
			unlockuserrequestdtoCall.setData(unlockuserrequestdtoBean);
			unlockuserrequestdtoCall.callService();			
			Logger.verifyIsContains("解锁原因不能为空",unlockuserrequestdtoCall.getString("LastErrorMessage"), "验证提示信息");
			Logger.verifyEquals("false",unlockuserrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100",unlockuserrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}